<template>
	<view></view>
</template>

<script>
import * as api from '../api/methods'
// import {getWebUrl} from "../api/methods";
  // import payment from '../components/payment'
	export default {
    components: {
      // payment
    },
		data() {
			return {
        // paylink: 'https://enjoy.test.abchina.com/mpaynew/mpay/index?token=16651989592449322108'
			}
		},
		onLoad: function (option) {
			if(option.action === 'pdf'){
				this.open_pdf(option.pdfPath)
				uni.navigateBack()
			}else if(option.action === 'login'){
				uni.redirectTo({
					url: '/pages/index/authorize'
				})
			}else if(option.action === 'signScan'){
				console.log('调用扫码接口2')
				let workOrderId = option.workOrderId
				// wx.scanCode({
				// 	// onlyFromCamera: true,
				// 	scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
				// 	success(res) {
				// 		console.log("888888",res)
				// 		let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。
				// 		let prevPage = pages[0]; 
				// 		let url = "/inspectionSign/"+workOrderId + "?scanInfo=" + encodeURI(res.result);
				// 		// prevPage.$vm.setUrl(url)
				// 	},
				// })
				// wx.navigateBack()
				uni.scanCode({
					onlyFromCamera: true,
					scanType: ['qrCode'],
					success: res => {
						console.log('已扫码');
						console.log(res.result)
						let pages = getCurrentPages(); //获取当前页面js里面的pages里的所有信息。
						let prevPage = pages[0];
						let canshu = encodeURI(res.result)
						if(canshu.indexOf('%EF%BB%BF')===-1){
							canshu = '%EF%BB%BF' +canshu
						}
						let url = "/inspectionSign/"+workOrderId + "?scanInfo=" +canshu +"&t="+new Date().getTime();
						console.log(url)
						prevPage.$vm.setUrl(url)
						uni.navigateBack()
					},
				});
			}
		},
		methods: {
			open_pdf(path){
    
				uni.downloadFile({
							url: api.getApiUrl()+'jkbppark/' + path,
							success: (res) => {
								console.log('成功')
								if (res.statusCode === 200) {
									// console.log('下载成功');
									var filePath = res.tempFilePath;
									uni.openDocument({
									  filePath: filePath,
									  showMenu: true,
									  success: function (res) {
										console.log('打开文档成功');
									  }
									});
								}
							},
				  error: err => {
					console.log('失败')
				  }
				});
			}
		}
	}
</script>

<style>
.payment-box{
  width: 100%;
  height: 80vh;
  position: absolute;
  left: 0;
  bottom: 0;
}
</style>
